import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class LoveComponentsService {

  private serviceUrls: any = {
    dictUrl: '/dict/detail', // 字典查询
    uploadFileUrl: '/common/upload/file', // 上传
    makeupSetupDataUrl: '/recycleOrder/getDiscountPlan', // 加价设置data
    updateMakeupSetupDataUrl: '/recycleOrder/updateMarkUp', // 加价设置保存
    userInfoUrl: '/customer/list', // 用户信息
  };

  constructor(public httpClient: HttpClient) { }

  /**
   * 用户信息
   * @param params 
   * @returns 
   */
  getUserInfo(params: any) {
    return this.httpClient.post(this.serviceUrls.userInfoUrl, params).toPromise();
  }

  /**
   * 字典查询
   * @param parentKey 
   * @returns 
   */
  dictListData(parentKey: any) {
    let params: any = {
      parentKey: parentKey,
      pageNum: 0,
      pageSize: 0
    };
    return this.httpClient.get(this.serviceUrls.dictUrl, { params: params }).toPromise();
  }

  /**
   * 文件上传
   * @param fileToUpload 
   * @returns 
   */
  uploadFileData(fileToUpload: File) {
    const formData: FormData = new FormData();
    formData.append('file', fileToUpload);
    formData.append('name', "love-recyc");
    return this.httpClient.post(this.serviceUrls.uploadFileUrl, formData).toPromise();
  }

  // 查询加价设置
  queryMakeupSetupData(params: any) {
    return this.httpClient.get(this.serviceUrls.makeupSetupDataUrl, { params }).toPromise();
  }

  // 保存修改加价设置
  updateMakeupSetupData(params: any) {
    return this.httpClient.post(this.serviceUrls.updateMakeupSetupDataUrl, params).toPromise();
  }
}



